﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using TouchRC.Logic;
using System.Drawing;
using System.Windows.Forms;

namespace TouchRC.BarManagers
{
    public class TopBarManager : FluidPanel
    {
        private FluidButton m_CloseButton;
        private FluidButton m_MinimiseButton;
        private FluidButton m_CancelButton;


        protected override void InitControl()
        {
            base.InitControl();

            Visible = false;
            BackColor = Color.Black;
            EnableDoubleBuffer = true;

            m_CloseButton = new FluidButton();
            m_CloseButton.BackColor = Color.Empty;
            m_CloseButton.Shape = ButtonShape.Flat;
            m_CloseButton.Image = ImageFactory.GetBitmap(ImageTypes.Cross);
            m_CloseButton.Click += new EventHandler(closeButton_Click);
            m_CloseButton.Visible = true;

            m_MinimiseButton = new FluidButton();
            m_MinimiseButton.BackColor = Color.Empty;
            m_MinimiseButton.Shape = ButtonShape.Flat;
            m_MinimiseButton.Image = ImageFactory.GetBitmap(ImageTypes.MenuUp);
            m_MinimiseButton.Click += new EventHandler(minimiseButton_Click);
            m_MinimiseButton.Visible = true;

            m_CancelButton = new FluidButton();
            m_CancelButton.BackColor = Color.Empty;
            m_CancelButton.Shape = ButtonShape.Flat;
            m_CancelButton.Image = ImageFactory.GetBitmap(ImageTypes.MenuDown);
            m_CancelButton.Click += new EventHandler(cancelButton_Click);
            m_CancelButton.Visible = true;

            Controls.Add(m_CloseButton);
            Controls.Add(m_MinimiseButton);
            Controls.Add(m_CancelButton);

            SetPositions();
        }

        public void SetPositions()
        {
            int margin = (5);

            int panelWidth = (3 * (AppSettings.ButtonDimensions)) + (4 * margin);
            int panelHeight = (2 * margin) + (AppSettings.ButtonDimensions);

            int xPos = (AppSettings.ScreenResolution.Width - panelWidth) / 2;
            int yPos = (AppSettings.ScreenResolution.Height - panelHeight) / 2;

            Bounds = new Rectangle(xPos, yPos, panelWidth, panelHeight);
            int buttonPos = margin;

            m_CloseButton.Bounds = new Rectangle(buttonPos, margin,
               AppSettings.ButtonDimensions, AppSettings.ButtonDimensions);

            buttonPos += margin + AppSettings.ButtonDimensions;

            m_MinimiseButton.Bounds = new Rectangle(buttonPos, margin,
               AppSettings.ButtonDimensions, AppSettings.ButtonDimensions);

            buttonPos += margin + AppSettings.ButtonDimensions;

            m_CancelButton.Bounds = new Rectangle(buttonPos, margin,
               AppSettings.ButtonDimensions, AppSettings.ButtonDimensions);
        }

        void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
            PasswordForm.Instance.Close();
        }

        void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void minimiseButton_Click(object sender, EventArgs e)
        {
            this.Close();
            PasswordForm.Instance.Hide();
        }

        public void ShowTopBar()
        {
            base.ShowModal(ShowTransition.None);
        }
    }
}
